home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / lib / dial / d_control.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-02-01  |  1.9 KB  |  80 lines

  1. #
  2. # include  "d_proto.h"
  3. # include  "d_returns.h"
  4.  
  5. /*
  6.  *    D_CONTROL
  7.  *
  8.  *    This routine tries to do something with unexpected
  9.  *    packet types.  If 'rdport' is looking for one packet
  10.  *    type and gets another, then this routine is called.
  11.  *    This allows certain control type packets to be sent
  12.  *    and processed without prior arrangements.  If the
  13.  *    packet is not one of these control packets, then an
  14.  *    error is returned.
  15.  *
  16.  *    packet - a pointer to the start of the packet.
  17.  *
  18. */
  19.  
  20. d_control (packet, length)
  21.   char *packet;
  22.   int length;
  23.     {
  24.     int dig1, dig2;
  25.     extern int d_nbuff, d_errno, d_rcvseq;
  26.  
  27.     /*  switch out to the code to process this packet  */
  28.     switch (packet[TYPEOFF])
  29.     {
  30.     case NBUFF:
  31.         /*  This is a control packet indicating whether buffering
  32.          *  is allowed.
  33.          */
  34.         dig1 = d_fromhex(packet[TEXTOFF]);
  35.         dig2 = d_fromhex(packet[TEXTOFF + 1]);
  36.  
  37.         /* This should stylistically be done elsewhere, but nobody
  38.          * else will know we got this packet. */
  39.         d_rcvseq = d_incseq (d_rcvseq);
  40.  
  41.         /*  Make sure the characters are reasonable  */
  42.         if ((dig1 < 0) ||
  43.         (dig2 < 0)   )
  44.         {
  45. #ifdef D_LOG
  46.         d_log ("d_control", "NBUFF: Bad hex char in packet ('%c%c')",
  47.                 packet[LHEADER], packet[LHEADER+1]);
  48. #endif D_LOG
  49.         return (D_NONFATAL);
  50.         }
  51.  
  52.         /*  transfer to the buffer counter  */
  53.         d_nbuff = (dig1 << 4) | dig2;
  54.         return (D_OK);
  55.  
  56.     case QUIT:
  57. #ifdef D_LOG
  58.         d_log ("d_control", "received QUIT packet");
  59. #endif D_LOG
  60.         if (length == LQUIT)
  61.         {
  62.         d_errno = D_RCVQUIT;
  63.         return (D_FATAL);
  64.         }
  65. #ifdef D_LOG
  66.         d_log ("d_control", "Quit packet bad length (%d)", length);
  67. #endif D_LOG
  68.         return (D_NONFATAL);
  69.  
  70.     default:
  71.         /*  If the packet type is not one of the special control
  72.          *  packets, then just log it as an error.
  73.          */
  74. #ifdef D_LOG
  75.         d_log ("d_control", "Bad packet type '%s'", packet);
  76. #endif D_LOG
  77.         return (D_NONFATAL);
  78.     }
  79. }
  80.